﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using esri.DataBase;
using esri.ParaSeting;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Controls;


namespace esri
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Form3 form3 = new Form3();
            form3.Show();
            form3.Initialize();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            Form4 form4 = new Form4();
            form4.Show();
            form4.Initialize();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //保存记录层和场的字符串            
            Paraseting PS = Paraseting.Instance();
            if (radioButton1.Checked == true)
                PS.UnitNo = comboBox1.Text + "1";
            else if (radioButton2.Checked == true)
                PS.UnitNo = comboBox1.Text + "2";
            else if (radioButton3.Checked == true)
                PS.UnitNo = comboBox1.Text + "3";
           // MessageBox.Show(textBox1.Text + "  " + textBox2.Text);
            PS.Point_Range = Convert.ToDouble(textBox1.Text);
            PS.Point_Grid_Range = Convert.ToDouble(textBox2.Text);
            //
            //完成设置，使TabControl可用
            //
            MainForm frmMF = (MainForm) this.Owner;
            frmMF.tabcontrol.Enabled = true;
            this.Close();
        }

        public void Initialize()
        {
            ///设置combobox中的内容为所有层的层号，
            ///从dbo.TABLE_UNITSCARS表中读出
            ///截取出层号 去掉重复的名称（重复是由于每一层有左中右三个场）

            //连接数据库
            DBConnection DBC = DBConnection.Instance();
            DBOperation DBO = new DBOperation();
            DBO.ConnectionString = DBC.ConnectionString;
            SqlConnection conn = DBO.Connect();

            string strSelect = "select UNITNO from dbo.TABLE_UNITSCARS";
            SqlCommand myCommand = new SqlCommand(strSelect, conn);
            SqlDataReader DataReader = myCommand.ExecuteReader();
            comboBox1.Items.Clear();
            comboBox1.BeginUpdate();
            while (DataReader.Read())
            { 
                string strUnitNo = DataReader.GetValue(0).ToString();
                if (strUnitNo.Length == 5)
                {
                    strUnitNo = strUnitNo.Substring(0, 4);
                    if (0 == comboBox1.Items.Count)
                    {                        
                        object oUnitNo = strUnitNo;
                        comboBox1.Items.Add(oUnitNo);
                    }
                    else
                    {
                        if (strUnitNo != comboBox1.Items[comboBox1.Items.Count - 1].ToString())
                        {
                            object oUnitNo = strUnitNo;
                            comboBox1.Items.Add(oUnitNo);
                        }
                    }
                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            MainForm frmMF = (MainForm) this.Owner;
            frmMF.MapControl.AddShapeFile(System.Windows.Forms.Application.StartupPath+@"\图层数据", "7372_shapefile.shp");
            IFeatureLayer pFeatureLayer = frmMF.MapControl.get_Layer(0) as IFeatureLayer;
            frmMF.MapControl.Refresh();

        }
    }
}
